const { contextBridge, ipcRenderer } = require("electron");

//获取地址页面与标题并保存
const sendUrl = async (url) => {
  let res = await ipcRenderer.invoke("on-url-event", url);
  return res;
};

//弹窗警告
const alert = (msg) => {
  ipcRenderer.invoke("on-alert-event", msg);
};

//打开网站
const open = (url) => {
  ipcRenderer.invoke("on-open-event", url);
};

//获取本地图片文件
const getFileList = async () => {
  let res = await ipcRenderer.invoke("on-get-files-event");
  return res;
};

//传递当前窗口的webContents,并传递当前页面
const sender = (isHome) => {
  ipcRenderer.send("on-sender-event", isHome);
};

//将vue组件中的setIsShow方法传递进来
const openDialog = (setIsShow) => {
  ipcRenderer.on("on-opendialog-event", () => {
    if (window.location.pathname !== "/home") {
      window.location.pathname = "/home";
    }
    setIsShow(true);
  });
};

contextBridge.exposeInMainWorld("myApi", { sendUrl, alert, open, getFileList, sender, openDialog });
